package 代码随想录_回溯.力扣_回溯.搜索矩阵.牛客;

import java.util.Scanner;

/**day_38
 * @author zx
 * @create 2022-08-22 13:00
 */
public class 红与黑 {
    /**
     * 改造成和剑指offer-13一样的做法
     */
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int m = sc.nextInt();
            int n = sc.nextInt();
            sc.nextLine();
            int x = 0, y = 0;
            boolean[][] used = new boolean[m][n];
            char[][] arr = new char[m][n];
            for(int i = 0;i < m;i++){
                String str = sc.nextLine();
                for(int j = 0;j < n;j++){
                    arr[i][j] = str.charAt(j);
                    if(arr[i][j] == '@'){//初始位置坐标
                        x = i;
                        y = j;
                    }
                }
            }
            int res = dfs(arr,x,y,used);
            System.out.println(res);
        }
    }
    private static int dfs(char[][] arr, int i, int j, boolean[][] used){
        if(i < 0 || i >= arr.length || j < 0 || j >= arr[0].length){
            return 0;
        }
        if(arr[i][j] == '#' || used[i][j]){
            return 0;
        }
        used[i][j] = true;
        return 1 + dfs(arr,i - 1,j,used) + dfs(arr,i + 1,j,used)
                + dfs(arr,i,j - 1,used) + dfs(arr,i,j + 1,used);
    }
}
